package cn.xdf.docscan.util

import android.content.Context
import android.graphics.Bitmap
import android.net.Uri
import androidx.core.content.FileProvider
import java.io.File
import java.io.FileOutputStream

object TempStore {
    fun storeBitmapAndGetUri(context: Context, bitmap: Bitmap): Uri {
        val dir = File(context.cacheDir, "rectified")
        if (!dir.exists()) dir.mkdirs()
        val file = File(dir, "rectified_${System.currentTimeMillis()}.jpg")
        FileOutputStream(file).use { fos ->
            bitmap.compress(Bitmap.CompressFormat.JPEG, 95, fos)
        }
        val authority = context.packageName + ".fileprovider"
        return FileProvider.getUriForFile(context, authority, file)
    }
}


